######################
#  Replication code for 'Mediating the Electoral Connection', forthcoming in the JOP
#  John Henderson and John Brooks
#  12/7/2015    
######################    

# figure4-plots.R
#  :: produces plots for slider results by incumbent term in office


rm(list=ls())
setwd('~/Dropbox/rainReplication')   
           
load('slider/figure4-4_3.Rdata')
      
dose_seq=as.numeric(rownames(coefs[[1]]))-1   
        
# borrow information from the other model ...
ci1=cbind(coefs[[1]][,1]+coefs[[1]][,2]*1.64,coefs[[1]][,1]-coefs[[1]][,2]*1.64)
ci2=cbind(coefs[[2]][,1]+coefs[[2]][,2]*1.64,coefs[[2]][,1]-coefs[[2]][,2]*1.64)

pdf('slider/seniority_slider_day.pdf')                          
par(cex.axis=.9)
plot(coefs[[1]][,1]~dose_seq,main='',xlab='Terms in Office',ylab='IV Estimate',ylim=c(-15,15),col='grey20',pch=19,axes=F)
for(i in 1:nrow(ci1)){
	lines(x=c(dose_seq[i],dose_seq[i]),y=c(ci1[i,1],ci1[i,2]),lty=2)  
}
axis(2)
lines(lowess(f=.6,coefs[[1]][,1]~dose_seq),col='grey20',lty=2)
axis(1,at=c(dose_seq),labels=dose_seq)
dev.off()
   
pdf('slider/seniority_slider_weekend.pdf')                                                 
par(cex.axis=.9)
plot(coefs[[2]][,1]~dose_seq,main='',xlab='Terms in Office',ylab='IV Estimate',ylim=c(-15,15),col='grey20',pch=19,axes=F)
for(i in 1:nrow(ci1)){
	lines(x=c(dose_seq[i],dose_seq[i]),y=c(ci2[i,1],ci2[i,2]),lty=2,col='grey20')	
}
axis(2)
lines(lowess(f=.6,coefs[[2]][,1]~dose_seq),col='grey10',lty=2)   
axis(1,at=c(dose_seq),labels=dose_seq)
dev.off()
              
# end